﻿app.controller("measureUnitController", function ($scope, measureUnitService, $window) {

    $scope.hola = function () {
        console.log($scope.name);
    }
    $scope.list = [];
   
    $scope.lis = function () {
        measureUnitService.getList().then(function (results) {
            $scope.list = results.data;
        }, function (error) {
            console.log(error.data.message);
        });
    }
    
    $scope.getById = function (measureUnit) {
        $scope.measureUnit = measureUnit;
    };

    $scope.save = function () {
        if ($scope.measureUnit.id) {
            measureUnitService.update({ id: "" }, $scope.measureUnit).then(function (results) {
                console.log(results.data);
                $scope.lis();
            }, function (error) {
                console.log(error.data.message);
            });
        } else {
            measureUnitService.create($scope.measureUnit).then(function (results) {
                console.log(results.data);
                $scope.lis();
            }, function (error) {
                console.log(error.data.message);
            });
        }
    }
    $scope.delete = function (measureUnit) {
        if ($window.confirm('Confirm delete')) {
            measureUnitService.delete({ id: measureUnit.id }).then(function (results) {
                console.log(results.data);
                $scope.lis();
            }, function (error) {
                console.log(error.data.message);
            });
        }
    }
    $scope.lis();

});